// CppCleanTest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <assert.h>
#include "../Tokenizer.h"
#include "../cppnode.h"

using namespace CppClean;

void TestTokenize()
{
	char* pSource = NULL;
	DWORD dwSize = CFileUtil::ReadFile(L"e:\\Learn\\CppClean\\test\\test.h", &pSource);
	CTokenizer t(pSource, dwSize);
	while(1)
	{
		CToken* pTok = t.GetNextToken();
		if(pTok == NULL)
			break;
		pTok->OutputDebug();
	}
	delete [] pSource;
};

void TestStringSplit()
{
	const char* test1 = " first   second   third ";
	const char* test2 = "  first second third   ";
	const char* test3 = "first second third";

	STRINGSET s1, s2, s3;
	CStringUtil::Split(s1, test1);
	CStringUtil::Split(s2, test2);
	CStringUtil::Split(s3, test3);

	CStringUtil::DumpSet(s1);
	CStringUtil::DumpSet(s2);
	CStringUtil::DumpSet(s3);

	s1.insert("");
	string sRet = CStringUtil::Join(s1, "::", "null");
	assert(sRet.compare("null::first::second::third") == 0);
	assert(CStringUtil::InSet("first", s1));
	assert(CStringUtil::InSet("second", s2));
	assert(CStringUtil::InSet("third", s3));
};

void TestType()
{
	CCpAutoPtr<CType> a1 = new CType(1,10, "string", CType::TYPE_LIST(), STRINGLIST(), FALSE, TRUE, FALSE);
	CCpAutoPtr<CType> a2 = new CType(11,100, "int", CType::TYPE_LIST(), STRINGLIST(), TRUE, FALSE, FALSE);

	CType::TYPE_LIST tmpl;
	tmpl.push_back(a1);
	tmpl.push_back(a2);
	a1 = NULL;
	a2 = NULL;
	CCpAutoPtr<CType> a3 = new CType(0, 100, "map", tmpl, STRINGLIST(), FALSE, FALSE, TRUE);
	CDbgUtil::myDebugOutputA(a3->GetString().c_str(), TRUE);
	tmpl.clear();

	assert(a3->GetString().compare("Type(0, 100, map<Type(1, 10, string*),Type(11, 100, int&)>[])") == 0);
	
	a3 = NULL;

	CCpAutoPtr<CToken> tk1 = new CToken(CToken::eTTSyntax, "\"", 0,0);
	CCpAutoPtr<CToken> tk2 = new CToken(CToken::eTTSyntax, "What's up?", 0,0);

	CToken::TOKEN_LIST tkl;
	tkl.push_back(tk1);
	tkl.push_back(tk2);
	tkl.push_back(tk1);

	CParameter param(0, 0, "ab", a3, tkl);
	CDbgUtil::myDebugOutputA(param.GetString().c_str(), TRUE);
};

void TestToType()
{
	char* pSource = "public std::basic_string<char, myTemplate<char> >, public myTemplate<int>::iterator";
	CTokenizer t(pSource, strlen(pSource));
	CToken::TOKEN_LIST tokens;
	while(1)
	{
		CCpAutoPtr<CToken> pTok = t.GetNextToken();
		if(pTok == NULL)
			break;
		tokens.push_back(pTok);
	}
	STRINGLIST strl;
	CTypeConverter coverter(strl);
	CType::TYPE_LIST results;
	coverter.ToType(tokens, results);

	string str = CStringUtil::JoinObject(results, ",", "");
	CDbgUtil::myDebugOutputA(str.c_str(), TRUE);
}

void TestToParameter(LPSTR source)
{
	char* pSource = source;
	CTokenizer t(pSource, strlen(pSource));
	CToken::TOKEN_LIST tokens;
	while(1)
	{
		CCpAutoPtr<CToken> pTok = t.GetNextToken();
		if(pTok == NULL)
			break;
		tokens.push_back(pTok);
	}
	STRINGLIST strl;
	CTypeConverter coverter(strl);
	CParameter::PARAM_LIST results;
	coverter.ToParameter(tokens, results);

	string str = CStringUtil::JoinObject(results, ",", "");
	CDbgUtil::myDebugOutputA(str.c_str(), TRUE);
}

int _tmain(int argc, _TCHAR* argv[])
{
//	TestTokenize();
//	TestType();
//	TestToType();
	TestToParameter("CToken::TOKEN_LIST& aParts,				//In\out \r\n \
		BOOL bRemoveName,						// \r\n \
		string& name,							//out \r\n \
		string& sTypeName,						//out\r\n \
		CType::TYPE_LIST& templTypes,			//out\r\n \
		STRINGLIST& aModifiers,					//out\r\n \
		CToken::TOKEN_LIST& aDefaults,			//out\r\n \
		CToken::TOKEN_LIST& aUnusedTokens,		//out\r\n \
		STRINGLIST& templSubs");
	TestToParameter("CToken::TOKEN_LIST& aTypeModifiers, bool bNewLine= true, map<int, string>::iterator a, ...");

	return 0;
}

